﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kinectver1._0
{
    /* yc: this class is being used to save all the replay stuff created from first semester, this isnt neccessarily needed for the final
     * project, but saving code and commenting out for build errors
     * this was in the main window. you can plug this in wherever if needed, and change the button names 
     * with stuff included in for the colormanagers to be shown and viewed. (using the variables)
     * 
    class replayViewer
    {
        KinectRecorder recorderz;
        KinectReplay replayz;
        private void replay_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog { Title = "Select filename", Filter = "Replay files|*.replay" };

            if (openFileDialog.ShowDialog() == true)
            {
                if (replayz != null)
                {
                    replayz.SkeletonFrameReady -= replay_SkeletonFrameReady;
                    replayz.ColorImageFrameReady -= replay_ColorImageFrameReady;
                    replayz.Stop();
                }
                Stream recordStream = File.OpenRead(openFileDialog.FileName);

                replayz = new KinectReplay(recordStream);

                replayz.SkeletonFrameReady += replay_SkeletonFrameReady;
                replayz.ColorImageFrameReady += replay_ColorImageFrameReady;
                replayz.DepthImageFrameReady += replay_DepthImageFrameReady;

                replayz.Start();
            }
        }

        private void save_Click(object sender, RoutedEventArgs e)
        {
            if (recorderz != null)
            {
                StopRecord();
                return;
            }

            SaveFileDialog saveFileDialog = new SaveFileDialog { Title = "Select filename", Filter = "Replay files|*.replay" };

            if (saveFileDialog.ShowDialog() == true)
            {
                DirectRecord(saveFileDialog.FileName);
            }
        }

        void DirectRecord(string targetFileName)
        {
            Stream recordStream = File.Create(targetFileName);
            recorderz = new KinectRecorder(KinectRecordOptions.Skeletons | KinectRecordOptions.Color, recordStream);
            save.Content = "Stop Recording";
        }

        void StopRecord()
        {
            if (recorderz != null)
            {
                recorderz.Stop();
                recorderz = null;
                save.Content = "Record";
                return;
            }
        }
     private void replay_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog { Title = "Select filename", Filter = "Replay files|*.replay" };

            if (openFileDialog.ShowDialog() == true)
            {
                if (replayz != null)
                {
                    replayz.SkeletonFrameReady -= replay_SkeletonFrameReady;
                    replayz.ColorImageFrameReady -= replay_ColorImageFrameReady;
                    replayz.Stop();
                }
                Stream recordStream = File.OpenRead(openFileDialog.FileName);

                replayz = new KinectReplay(recordStream);

                replayz.SkeletonFrameReady += replay_SkeletonFrameReady;
                replayz.ColorImageFrameReady += replay_ColorImageFrameReady;
                replayz.DepthImageFrameReady += replay_DepthImageFrameReady;

                replayz.Start();
            }
        }
     * 
     * 
      void kinectRuntime_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            if (replayz != null && !replayz.IsFinished)
                return;

            using (var frame = e.OpenColorImageFrame())
            {
                if (frame == null)
                    return;

                if (recorderz != null && ((recorderz.Options & KinectRecordOptions.Color) != 0))
                {
                    recorderz.Record(frame);
                }

                if (displayDepth)
                    return;

                colorMan.Update(frame);
            }
        }
        //depth sensor
        void kinectSensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            if (replayz != null && !replayz.IsFinished)
                return;

            using (var frame = e.OpenDepthImageFrame())
            {
                if (frame == null)
                    return;

                if (recorderz != null && ((recorderz.Options & KinectRecordOptions.Depth) != 0))
                {
                    recorderz.Record(frame);
                }

                if (!displayDepth)
                    return;

                depthMan.Update(frame);
            }
        }
        //skel camera
        void kinectRuntime_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            if (replayz != null && !replayz.IsFinished)
                return;
            using (SkeletonFrame frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                    return;

                if (recorderz != null && ((recorderz.Options & KinectRecordOptions.Color) != 0))
                    recorderz.Record(frame);
                frame.GetSkeletons(ref allSkeletons);

                if (allSkeletons.All(s => s.TrackingState == SkeletonTrackingState.NotTracked))
                    return;

                ProcessFrame(frame);
            }
        }
    }
     void replay_DepthImageFrameReady(object sender, ReplayDepthImageFrameReadyEventArgs e)
        {
            if (!displayDepth)
                return;

            depthMan.Update(e.DepthImageFrame);
        }
        
        void replay_ColorImageFrameReady(object sender, ReplayColorImageFrameReadyEventArgs e)
        {
            if (displayDepth)
                return;

            colorMan.Update(e.ColorImageFrame);
        }


        void replay_SkeletonFrameReady(object sender, ReplaySkeletonFrameReadyEventArgs e)
        {
            ProcessFrame(e.SkeletonFrame);
        }
        
    */
}
